{% extends 'base.html' %}
{% block title %}
    <a class="navbar-brand" href="#"> 员工离职信息 </a>
{% endblock %}
{% block content %}
    {# 使用 length 过滤器获取 staffs 变量的长度 #}
    {% if current_user.has_role('Admin') or current_user.has_role('Root') %}

    {% endif %}
    {% if current_user.has_role('Admin') or current_user.has_role('Root') %}
        <div class="content">
            <h4 class="title">员工离职信息</h4>
            <div class="toolbar">
                <!--        Here you can write extra buttons/actions for the toolbar              -->
                <form method="post">
                    查询方式
                    <select name="info" required>
                        <option value="userID">员工号</option>
                        <option value="username">员工姓名</option>
                        <option value="departmentname">部门名称</option>
                        <option value="postname">岗位名称</option>
                        <option value="dimission_type">离职类型</option>
                        <option value="termdate">时间</option>
                    </select>
                    <input type="text" name="date" autocomplete="off" required>
                    <input type="submit" name="submit" value="查询">
                </form>

            </div>
            {% if info == 'userID' or info == 'username' %}
                <div class="material-datatables">
                    <table id="datatables" class="table table-striped table-no-bordered table-hover"
                           style="width:100%;cellspacing:0">
                        <thead>
                        <tr>
                            <th>员工号</th>
                            <th>姓名</th>
                            <th>部门</th>
                            <th>岗位</th>
                            <th>时间</th>
                            <th>类型</th>
                            <th>去向</th>
                            <th>人才库</th>
                            <th>备注</th>
                            <th class="disabled-sorting text-right">操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        <tr>
                            <td>{{ staffs.userID }}</td>
                            <td>{{ staffs.username }}</td>
                            <td>{{ departments.departmentname }}</td>
                            <td>{{ posts.postname }}</td>
                            <td>{{ staff_dimissions.termdate }}</td>
                            <td>{{ staff_dimissions.dimission_type }}</td>
                            <td>{{ staff_dimissions.leave_to }}</td>
                            <td>{{ staff_dimissions.talent_pool }}</td>
                            <td>{{ staff_dimissions.remark }}</td>
                            <td class="text-right">
                                <a href="{{ url_for('change_staff_dimission',userID=staffs.userID) }}"
                                   class="btn btn-simple btn-info btn-icon like">修改</a>
                            </td>
                        </tr>
                        </tbody>

                    </table>
                </div>
            {% else %}

                <div class="material-datatables">
                    <table id="datatables" class="table table-striped table-no-bordered table-hover"
                           style="width:100%;cellspacing:0">
                        <thead>
                        <tr>
                            <th>员工号</th>
                            <th>姓名</th>
                            <th>部门</th>
                            <th>岗位</th>
                            <th>时间</th>
                            <th>类型</th>
                            <th>去向</th>
                            <th>人才库</th>
                            <th>备注</th>
                            <th class="disabled-sorting text-right">操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        {% for staff in staffs %}
                            {% for staff_dimission in staff_dimissions %}
                                {% if staff.userID == staff_dimission.userID %}
                                    <tr>
                                        <td>{{ staff.userID }}</td>
                                        <td>{{ staff.username }}</td>

                                        {% if info == 'departmentname' %}
                                            <td>{{ departments.departmentname }}</td>
                                        {% else %}
                                            {% for department in departments %}
                                                {% if staff.departmentID == department.departmentID %}
                                                    <td>{{ department.departmentname }}</td>
                                                {% endif %}
                                            {% endfor %}
                                        {% endif %}
                                        {% if info == 'postname' %}
                                            <td>{{ posts.postname }}</td>
                                        {% else %}
                                            {% for post in posts %}
                                                {% if staff.postID == post.postID %}
                                                    <td>{{ post.postname }}</td>
                                                {% endif %}
                                            {% endfor %}
                                        {% endif %}
                                        <td>{{ staff_dimission.termdate }}</td>
                                        <td>{{ staff_dimission.dimission_type }}</td>
                                        <td>{{ staff_dimission.leave_to }}</td>
                                        <td>{{ staff_dimission.talent_pool }}</td>
                                        <td>{{ staff_dimission.remark }}</td>
                                        <td class="text-right">
                                            <a href="{{ url_for('change_staff_dimission',userID=staff.userID) }}"
                                               class="btn btn-simple btn-info btn-icon like">修改</a>
                                        </td>
                                    </tr>
                                {% endif %}
                            {% endfor %}
                        {% endfor %}
                        </tbody>

                    </table>
                </div>


            {% endif %}
        </div>
    {% endif %}
{% endblock %}